package com.neusoft.neuiotms.dcom.task.maintain.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;

import com.google.common.eventbus.AsyncEventBus;
import com.neusoft.neuiotms.common.service.SerialNumberService;
import com.neusoft.neuiotms.dcom.repository.MaintainPlanRepository;
import com.neusoft.neuiotms.dcom.service.MaintainTaskService;
import com.neusoft.neuiotms.dcom.util.SendingMessageDcom;

/**
 * Quartz Scheduler configuration，自定义SchedulerFactoryBean，在具体job中可以拿到一些可用组件 <br>
 * 在QuartzJobBean实现类定义中，可以根据变量定义，自动拿到schedulerContext中值
 *
 * @author wys
 * @date 2020年7月27日 上下午10:06:34
 */
@Component
public class SchedulerFactoryBeanCustomizerImpl implements SchedulerFactoryBeanCustomizer {

    @Autowired
    private MaintainPlanRepository maintainPlanRepository;
    @Autowired
    private SendingMessageDcom sendingMessage;
    @Autowired
    private MaintainTaskService maintainTaskService;
    @Autowired
    private SerialNumberService serialNumberService;
    @javax.annotation.Resource(name = "modelUpdateEventBus")
    private AsyncEventBus modelUpdateEventBus;

    @Override
    public void customize(final SchedulerFactoryBean schedulerFactoryBean) {
        final Map<String, Object> schedulerContext = new HashMap<>();
        schedulerContext.put("maintainPlanRepository", this.maintainPlanRepository);
        schedulerContext.put("sendingMessage", this.sendingMessage);
        schedulerContext.put("maintainTaskService", this.maintainTaskService);
        schedulerContext.put("serialNumberService", this.serialNumberService);
        schedulerContext.put("modelUpdateEventBus", this.modelUpdateEventBus);
        schedulerFactoryBean.setSchedulerContextAsMap(schedulerContext);
    }

}
